package org.itboys.mobile.controller.web.wallet;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mysql.wallet.CooWalletRecord;
import org.itboys.mobile.service.mysql.web.wallet.CooWalletRecordService;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2018/2/1
 * 描述：钱包记录
 */
@Controller
@RequestMapping("/coo/web/wallet/record")
public class CooWalletRecordController extends BaseController{
    @Autowired
    private CooWalletRecordService recordService;
    @RequestMapping("/index")
    public String index(HttpServletRequest request,
                        @RequestParam(value="memberId",required=true)Long memberId,
                        Model model){
        model.addAttribute("memberId",memberId);
        return "/newcoo/wallet/record/index";
    }

    /**
     * 查询
     * @param request
     * @param response
     */
    @RequestMapping("/select")
    public void select(HttpServletRequest request,
                       HttpServletResponse response,
                       @RequestParam(value="memberId",required=true)Long memberId){
        try{
            PageResult<CooWalletRecord> result=recordService.selectRecord(request,memberId);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        }catch (Exception e){
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }

    }
}
